package com.orangelife.initialize;

import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class EncrypPropertyPlaceholderConfigurer extends
		PropertyPlaceholderConfigurer {
	protected void processProperties(
			ConfigurableListableBeanFactory beanFactory, Properties props)
			throws BeansException {
		try {
			/**
			 * 数据库用户名
			 */
			String username = props.getProperty("jdbc.username");
			if (username != null) {
				props.setProperty("jdbc.username", DESUtil.webDecrypt(username));
			}
			/***
			 * 数据库密码
			 */
			String password = props.getProperty("jdbc.password");
			if (password != null) {
				props.setProperty("jdbc.password", DESUtil.webDecrypt(password));
			}

			/**
			 * 数据库请求地址
			 */
			String url = props.getProperty("jdbc.url");
			if (url != null) {
				props.setProperty("jdbc.url", DESUtil.webDecrypt(url));
			}

			/**
			 * 数据库驱动
			 */
			String driver = props.getProperty("jdbc.driver");
			if (driver != null) {
				props.setProperty("jdbc.driver", DESUtil.webDecrypt(driver));
			}
			super.processProperties(beanFactory, props);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BeanInitializationException(e.getMessage());
		}
	}

}
